#include "swf_video_servlet.h"
#include "video_thread.h"

namespace vmon_web
{
    SwfVideoServlet::SwfVideoServlet()
    {
		m_videoThread = new VideoThread();
    }

    SwfVideoServlet::~SwfVideoServlet()
    {
    }

	bool SwfVideoServlet::handleRequest(WebSockHolder* sockHolder)
	{
		if (sockHolder->getRequest().getPath() == "/live.swf")
		{
			// this is a live show...
			HttpResponse& response = sockHolder->getResponse();
			response.addKeyword("Content-Type", "application/x-shockwave-flash");
            response.addKeyword("Server", "vmon");
            response.sendHead("200 OK");
			// TODO: we need a background thread to handle all swf connections
			// TODO: send back header first
			// TODO: the background thread encodes frames and sends back video stream
			m_videoThread->addSockHolder(sockHolder);
		}
		return true;
	}

    bool SwfVideoServlet::handleRequest(HttpRequest& request, HttpResponse& response)
    {
        if (request.getPath() == "/live.swf")
        {
            // TODO: add support for live swf video
            response.send("HTTP/1.1 200 OK\r\n");
            response.send("Content-Type: text/html; charset=utf-8\r\n");
            response.send("\r\n");
            response.send("<html><body><h1>Swf not implemented now</h1></body></html>\r\n");
        }
        return false;
    }
}
